<?php
/* add user to database */

	include('config/config.php');
	include('config/funcs.php');
	global $CONFIG;
// connect to the database
	$link = mysql_connect($CONFIG['dbserver'], $CONFIG['dbuser'], $CONFIG['dbpass']);

/* check database connection */
	if (!$link) {
		           die('Not connected : ' . mysql_error());
	}
	
/* these variables are passed from index.php */
	$user=$_POST['defineUser'];
	$perms=$_POST['dbPerms'];
	$dbAdd=$_POST['defineDb'];

	$dbQuery="GRANT ".$perms." ON ".$dbAdd.".* TO ".$user."@".$CONFIG['dbserver'];
	
	echo $dbQuery."<br />";
	$result = mysql_query($dbQuery);

/* check to see if the mysql query went through properly */	

	if (!$result) {
			echo "Somethin aint right, Jimbo! ".mysql_error();
			echo "<a href=\"index.php\">Back</a>";
	}
	else {
			echo "YAY! User successfully added to the database!";
			echo "<a href=\"index.php\">Back</a>";
	}

?>
